package hyit.app.dao.proxy;

import java.util.List;

import hyit.app.dao.IAttendanceGroupDAO;
import hyit.app.dao.impl.AttendanceGroupDAOImpl;
import hyit.app.dbc.DatabaseConnection;
import hyit.app.model.AttendanceGroup;

public class AttendanceGroupDAOProxy implements IAttendanceGroupDAO {
	private DatabaseConnection dbc = null;
	private IAttendanceGroupDAO dao = null;

	public AttendanceGroupDAOProxy() throws Exception {
		this.dbc = new DatabaseConnection();
		this.dao = new AttendanceGroupDAOImpl(this.dbc.getConnection());
	}

	@Override
	public boolean doCreate(AttendanceGroup attendanceGroup) throws Exception {
		boolean flag = false;
		try {
			if (this.dao.findBySubject(attendanceGroup.getSubjectNumber()) == null) {
				flag = this.dao.doCreate(attendanceGroup);
			}
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return flag;
	}

	@Override
	public boolean update(AttendanceGroup attendanceGroup) throws Exception {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public AttendanceGroup findBySubject(Integer number) throws Exception {
		AttendanceGroup attendanceGroup = null;
		try {
			attendanceGroup = this.dao.findBySubject(number);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return attendanceGroup;
	}

	@Override
	public List<AttendanceGroup> findByDepartment(Integer number)
			throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

}
